package com.eposi.eposigameinterface;

import com.eposi.eposigameinterface.view.ViewCommon;
import com.eposi.eposigameinterface.view.ViewDeposit;
import com.eposi.eposigameinterface.view.ViewHelp;
import com.eposi.eposigameinterface.view.ViewProfile;
import com.eposi.eposigameinterface.view.ViewSetting;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public abstract class MenuActivity extends FragmentActivity {
	private LinearLayout layoutMenu;
	private LinearLayout layoutContent;
	private LinearLayout topBtnCommon;
	private LinearLayout topBtnCash;
	private LinearLayout topBtnSetting;
	private LinearLayout topBtnHelp;
	private LinearLayout topBtnProfile;
	boolean isProfileShow = false;
	boolean isCommonShow = false;
	boolean isCashShow = false;
	boolean isSettingShow = false;
	boolean isHelpShow = false;
	private int bkgTopBtn;
	private ImageButton topBtnBack;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.activity_abs);
		topBtnBack = (ImageButton) findViewById(R.id.top_bar_btn_back);
		topBtnProfile = (LinearLayout) findViewById(R.id.top_bar_btn_profile);
		topBtnCommon = (LinearLayout) findViewById(R.id.top_bar_btn_common);
		topBtnCash = (LinearLayout) findViewById(R.id.top_bar_btn_cash);
		topBtnSetting = (LinearLayout) findViewById(R.id.top_bar_btn_settings);
		topBtnHelp = (LinearLayout) findViewById(R.id.top_bar_btn_help);
		layoutContent = (LinearLayout) findViewById(R.id.activity_abs_layout_content);
		layoutMenu = (LinearLayout) findViewById(R.id.activity_abs_layout_menu);
		bkgTopBtn = R.drawable.btn_top_forcus;
		topBtnProfile.setOnClickListener(topBtnProfileListener);
		topBtnCommon.setOnClickListener(topBtnCommonListener);
		topBtnCash.setOnClickListener(topBtnCashListener);
		topBtnSetting.setOnClickListener(topBtnSettingListener);
		topBtnHelp.setOnClickListener(topBtnHelpListener);
		topBtnBack.setOnClickListener(topBtnBackListener);

	}

	protected void setViewContent(int layout) {
		View view = this.getLayoutInflater().inflate(layout, null);
		setViewContent(view);
	}

	protected void setViewContent(View layout) {
		layoutContent.removeAllViewsInLayout();
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT);
		layoutContent.addView(layout, params);
	}

	protected void setViewMenu(View layout) {
		layoutMenu.setVisibility(View.VISIBLE);
		layoutMenu.removeAllViewsInLayout();
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT);
		layoutMenu.addView(layout, params);
	}

	protected void hideLayoutMenu() {
		layoutMenu.removeAllViewsInLayout();
		layoutMenu.setVisibility(View.GONE);
	}

	/**
	 * Listener
	 */
	OnClickListener topBtnProfileListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			setTransparentButtonTop();
			if (isProfileShow) {
				isProfileShow = false;
				topBtnProfile.setBackgroundColor(Color.TRANSPARENT);
				hideLayoutMenu();
			} else {
				isCommonShow = false;
				isCashShow = false;
				isSettingShow = false;
				isHelpShow = false;
				isProfileShow = true;
				topBtnProfile.setBackgroundResource(bkgTopBtn);
				ViewProfile profile = new ViewProfile(MenuActivity.this);
				setViewMenu(profile);
			}
		}
	};
	OnClickListener topBtnCommonListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			setTransparentButtonTop();
			if (isCommonShow) {
				isCommonShow = false;
				topBtnCommon.setBackgroundColor(Color.TRANSPARENT);
				hideLayoutMenu();
			} else {
				isProfileShow = false;
				isCashShow = false;
				isSettingShow = false;
				isHelpShow = false;
				isCommonShow = true;
				topBtnCommon.setBackgroundResource(bkgTopBtn);
				ViewCommon common = new ViewCommon(MenuActivity.this);
				setViewMenu(common);
			}
		}
	};
	OnClickListener topBtnCashListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			setTransparentButtonTop();
			if (isCashShow) {
				isCashShow = false;
				topBtnCash.setBackgroundColor(Color.TRANSPARENT);
				hideLayoutMenu();
			} else {
				isProfileShow = false;
				isCommonShow = false;
				isSettingShow = false;
				isHelpShow = false;
				isCashShow = true;
				topBtnCash.setBackgroundResource(bkgTopBtn);
				ViewDeposit deposit = new ViewDeposit(MenuActivity.this);
				setViewMenu(deposit);
			}
		}
	};
	OnClickListener topBtnSettingListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			setTransparentButtonTop();
			if (isSettingShow) {
				isSettingShow = false;
				topBtnSetting.setBackgroundColor(Color.TRANSPARENT);
				hideLayoutMenu();
			} else {
				isProfileShow = false;
				isCommonShow = false;
				isCashShow = false;
				isHelpShow = false;
				isSettingShow = true;
				topBtnSetting.setBackgroundResource(bkgTopBtn);
				ViewSetting setting = new ViewSetting(MenuActivity.this);
				setViewMenu(setting);
			}
		}
	};
	OnClickListener topBtnHelpListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			setTransparentButtonTop();
			if (isHelpShow) {
				isHelpShow = false;
				topBtnHelp.setBackgroundColor(Color.TRANSPARENT);
				hideLayoutMenu();
			} else {
				isProfileShow = false;
				isCommonShow = false;
				isCashShow = false;
				isSettingShow = false;
				isHelpShow = true;
				topBtnHelp.setBackgroundResource(bkgTopBtn);
				ViewHelp help = new ViewHelp(MenuActivity.this);
				setViewMenu(help);
			}
		}
	};
	OnClickListener topBtnBackListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			finish();
		}
	};
	
	public void setTransparentButtonTop() {

		topBtnProfile.setBackgroundColor(Color.TRANSPARENT);
		topBtnCommon.setBackgroundColor(Color.TRANSPARENT);
		topBtnCash.setBackgroundColor(Color.TRANSPARENT);
		topBtnSetting.setBackgroundColor(Color.TRANSPARENT);
		topBtnHelp.setBackgroundColor(Color.TRANSPARENT);
	}
}
